#!/bin/bash

#set -o pipefail
set -o errexit
export LC_ALL=C

ANNOTATE_DIR=$1
BASE_ANN_DIR=$ANNOTATE_DIR/../

export BASE_DATE=$(head -n1 ${BASE_ANN_DIR}/base_date.txt)
export BASE_DATA_PATH=/home/mixagol/data/
# export BASE_DATA_PATH=/home/mixagol/data2/

source 6_annotation/annotate_common.sh

# NORM_MATRIX_DIR=${BASE_DATA_PATH}/4_normed_matrix/${BASE_DATE}/wu_blast_nw # full
# NORM_MATRIX_DIR=${BASE_DATA_PATH}/4_normed_matrix/${BASE_DATE}/wu_blast_nw_excl_NC_010163 # a.laidlawii
NORM_MATRIX_DIR=${BASE_DATA_PATH}/4_normed_matrix/${BASE_DATE}/wu_blast_nw_excl_NC_010102 # s.enterica
# NORM_MATRIX_DIR=${BASE_DATA_PATH}/4_normed_matrix/${BASE_DATE}/wu_blast_nw_excl_NC_012883 # t.sibiricus

GENOMES_NUM=`cat "${NORM_MATRIX_DIR}/map_int_genom.txt" | wc -l`

ANNOTATE_DIR=$1
EXCL_GENOMES=$(head -n1 ${BASE_ANN_DIR}/excl_genomes.txt)

for Z_VALUE in 3 4 5; do
    E_DIR=$ANNOTATE_DIR/e_$Z_VALUE
    mkdir -p $E_DIR

    create_vectors_nw      $ANNOTATE_DIR    $E_DIR    $Z_VALUE    $NORM_MATRIX_DIR   $EXCL_GENOMES
    find_sim_vectors_raw                    $E_DIR    $Z_VALUE    $NORM_MATRIX_DIR   $GENOMES_NUM
    find_sim_vectors                        $E_DIR    $Z_VALUE    $NORM_MATRIX_DIR
    create_kegg_limited                     $E_DIR    $Z_VALUE    "1e-7"
    create_gene_functions                   $E_DIR    $Z_VALUE
    create_gene_functions_kegg              $E_DIR    $Z_VALUE
    create_gene_functions_uniq              $E_DIR    $Z_VALUE
    create_gene_functions_best_uniq         $E_DIR    $Z_VALUE
    create_gene_functions_best_uniq_kegg    $E_DIR    $Z_VALUE
    create_gene_ontology                    $E_DIR    $Z_VALUE    "1e-7"

done

